package co.edu.unal.util;

import java.awt.Rectangle;

public class BoundBox extends Rectangle {

	private static final long serialVersionUID = 1L;


	public BoundBox(int x1, int y1, int x2, int y2) {
		this(x1, y1, x2, y2, true);
	}

	public BoundBox(int x1, int y1, int x2, int y2, boolean normalize) {
		super(x1, y1, x2 - x1, y2 - y1);

		if (normalize) {
			normalize();
		}
	}

	private void normalize() {
		int x1 = x;
		int y1 = y;
		int x2 = x1 + width;
		int y2 = y1 + height;

		if (x1 > x2) {
			x = x2;
		}

		if (y1 > y2) {
			y = y2;
		}

		width = Math.abs(width);
		height = Math.abs(height);

	}

	public String toString() {
		return ("x1=" + x + ", y1=" + y + ", x2=" + (x + width) + ", y2=" + (y + height));
	}


	public static void main(String[] args) {
		BoundBox bbox = new BoundBox(100, 200,50,150);
		System.out.println(bbox);
	}
}